﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplicationFileSys.Models
{
    public class PageMode<T >
    {
        public int PageIndex { get; set; }
        public int PageSize { get; set; }
        public int TotalCount { get; set; }
        public List<T> Items { get; set; }
        public int TotalPages
        {
            get { return (int)Math.Ceiling((decimal)TotalCount / PageSize); }
        }

        public PageMode(int pageIndex, int pageSize, int totalCount)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = totalCount;
        }
        public List<T> GetPagedData(List<T> dataList)
        {
            return dataList.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
        }
        public bool HasPreviousPage
        {
            get { return PageIndex > 1; }
        }

        public bool HasNextPage
        {
            get { return PageIndex < TotalPages; }
        }

        public int PreviousPage
        {
            get { return PageIndex - 1; }
        }

        public int NextPage
        {
            get { return PageIndex + 1; }
        }

        public int FirstPage
        {
            get { return 1; }
        }

        public int LastPage
        {
            get { return TotalPages; }
        }

        public int GetStartIndex()
        {
            return (PageIndex - 1) * PageSize;
        }

        public int GetEndIndex()
        {
            return PageIndex * PageSize;
        }
    }
}